<?php

/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: admincp_search.php 7020 2010-03-28 06:32:08Z cnteacher $
 */

if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}

cpheader();

$keywords = trim($_G['gp_keywords']);
$results = array();
$kws = explode(' ', $keywords);
$kws = array_map('trim', $kws);
$keywords = implode(' ', $kws);

if($_G['gp_searchsubmit'] && $keywords) {
	foreach($lang as $key => $value) {
		$matched = TRUE;
		foreach($kws as $kw) {
			if(strpos(strtolower($value), strtolower($kw)) === FALSE) {
				$matched = FALSE;
				break;
			}
		}
		if($matched) {
			$tmp = explode('_', $key);
			if(!in_array($tmp[0], $admincp_actions_normal)) {
				continue;
			}
			$url = ADMINSCRIPT.'?action='.$tmp[0];
			$vname = $tmp[0];
			$subject = cplang($vname);
			if($tmp[1]) {
				$url .= '&operation='.$tmp[1];
				$subject = cplang($vname.'_'.$tmp[1]);
			}
			$subject = '<a href="'.$url.'&highlight='.urlencode($keywords).'"><u>'.$subject.'</u></a>';
			if(isset($results[$url])) {
				$results[$url]['message'] .= '<br />'.$value;
			} else {
				$results[$url] = array('subject' => $subject, 'message' => $value);
			}

		}
	}

	if($results) {
		showsubmenu('search_result');
		foreach($results as $result) {
			echo '<div class="news"><h3>'.$result[subject].'</h3><p class="lineheight">'.strip_tags($result[message], '<br>').'</p></div>';
		}
		echo <<<EOT
<script type="text/JavaScript">
function parsetag(tag) {
	var str = $('cpcontainer').innerHTML.replace(/(^|>)([^<]+)(?=<|$)/ig, function($1, $2, $3) {
		if(tag && $3.indexOf(tag) != -1) {
			$3 = $3.replace(tag, '<h_>');
		}
		return $2 + $3;
		});
	$('cpcontainer').innerHTML = str.replace(/<h_>/ig, function($1, $2) {
		return '<font color="#c60a00">' + tag + '</font>';
		});
}
EOT;
		foreach($kws as $kw) {
			echo 'parsetag(\''.$kw.'\');';
		}
		echo '</script>';

	} else {
		cpmsg('search_result_noexists');
	}

} else {
	cpmsg('search_keyword_noexists', '', 'error');
}

?>